{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import openpyxl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "data": {
      "text/plain": "<openpyxl.workbook.workbook.Workbook at 0x1f443b79c40>"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myBook=openpyxl.load_workbook('收入表.xlsx')\n",
    "myBook"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "data": {
      "text/plain": "<generator object Worksheet.values at 0x000001F4645DCA50>"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myBook.worksheets[0].values"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "data": {
      "text/plain": "[('华茂集团子公司营业收入表', None, None, None, None),\n (None, None, None, None, None),\n ('编制单位：', None, None, None, None),\n ('季  度', '家电收入', '建材收入', '其他收入', '合   计'),\n ('1季度', 296719, 203358, 5613, None),\n ('2季度', 373445, 138815, 445, None),\n ('3季度', 496008, 168123, 1246, None),\n ('4季度', 120234, 499028, 118896, None)]"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "myRows=list(myBook.worksheets[0].values)\n",
    "myRows"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [],
   "source": [
    "myRowIndex=4"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [],
   "source": [
    "while myRowIndex<len(myRows):\n",
    "\tmyRowSum=sum(myRows[myRowIndex][1:4])\n",
    "\tmyBook.worksheets[0].cell(myRowIndex+1,5).value=myRowSum\n",
    "\tmyRowIndex+=1"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [],
   "source": [
    "myBook.save('结果表-收入表.xlsx')"
   ],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
